export default {
    state: {
        isCollapse: false,
        tabsList: [
            {
            path: "/home",
            name: "home",
            label: "首页",
            icon: "s-home",
            }
        ],
        currentMenu:null,
        Menu:[],
    },
    actions: {
        incrementAsync ({ commit }) {
          setTimeout(() => {
            commit('increment')
          }, 1000)
        }
      },
    mutations: {
        selectisadministrator(state,val){
            const MENUS='menus'
            if(val !== true){
                state.Menu=  [
                    {
                      path: "/",
                      name: "home",
                      label: "仪表盘",
                      icon: "s-home",
                      url: "Home/Home"
                    },
                    {
                      path: "/mall",
                      name: "mall",
                      label: "文章管理",
                      icon: "video-play",
                      url: "MallManage/MallManage"
                    },
                    {
                      label: "其他",
                      icon: "location",
                      children: [
                        {
                          path: "/page1",
                          name: "page1",
                          label: "更换头像",
                          icon: "setting",
                          url: "Other/PageOne"
                        },
                        {
                          path: "/page2",
                          name: "page2",
                          label: "页面2",
                          icon: "setting",
                          url: "Other/PageTwo"
                        }
                      ]
                    }
                  ]
                  sessionStorage.setItem(MENUS,JSON.stringify(state.Menu));
            }else {
                state.Menu= [
                    {
                      path: "/",
                      name: "home",
                      label: "仪表盘",
                      icon: "s-home",
                      url: "Home/Home"
                    },
                    {
                      path: "/mall",
                      name: "mall",
                      label: "文章管理",
                      icon: "video-play",
                      url: "MallManage/MallManage"
                    },
                    {
                      path: "/user",
                      name: "user",
                      label: "用户管理",
                      icon: "user",
                      url: "UserManage/UserManage"
                    },
                    {
                      label: "其他",
                      icon: "location",
                      children: [
                        {
                          path: "/page1",
                          name: "page1",
                          label: "更换头像",
                          icon: "setting",
                          url: "Other/PageOne"
                        },
                        {
                          path: "/page2",
                          name: "page2",
                          label: "页面2",
                          icon: "setting",
                          url: "Other/PageTwo"
                        }
                      ]
                    }
                  ]
                  sessionStorage.setItem(MENUS,JSON.stringify(state.Menu));
            }
        },
        changeCollapse(state) {
            state.isCollapse=!state.isCollapse
        },
        selectMenu(state, val) {
            if (val.name !=='home') {
                state.currentMenu = val;
                const result = state.tabsList.findIndex(item => item.name === val.name)
                if (result === -1) {
                    state.tabsList.push(val)
                }
            } else {
                state.currentMenu = null
            }
        }, 
        // 删除Tag
        closeTag(state,val) {
            const delTag = state.tabsList.findIndex(item => item.name === val.name);
            if (delTag !== -1) {
                state.tabsList.splice(delTag,1)
            }
        }
    }
}